package pages;
import java.io.File;
import java.lang.reflect.Field;
import java.util.HashMap;

import common.ReadPageXML;

//This class reads the Google Search Page XML file and creates the variables with the values specified in XML file.
public class GoogleSearchPage {

	public String GoogleSearch;
	public String GoogleHelp;
	public String GoogleAbout;
	
	public GoogleSearchPage() {
		
		String pageFileName = this.getClass().getSimpleName();
		System.out.println("Calling class name is " + pageFileName);
		
		//form the xml file path
		File directory = new File (".");
		String absPath = null;
		try {
			System.out.println ("Current directory's absolute  path: " 
					+ directory.getAbsolutePath());
			absPath = new String(directory.getAbsolutePath());
		}catch(Exception e) {
			 	System.out.println("Exceptione is ="+e.getMessage());
		}
         
		String temp [] = null;
		temp = absPath.split("\\.");
		String xmlPath = temp[0] + "src\\Pages\\xml\\" + pageFileName + ".xml";
		System.out.println("Xml file path is => " + xmlPath);

		//call the function to parse the xml 
		ReadPageXML xml_parser = new ReadPageXML();
		HashMap<String, String> map = xml_parser.parseXML(xmlPath);

		System.out.println("Map value of GoogleSearch =>  " + map.get("GoogleSearch"));
		Field[] fields = GoogleSearchPage.class.getFields();
		System.out.println("Field length = " + fields.length);
		
		for (int k = 0; k < fields.length; k++) {
			if (fields[k].getName().equalsIgnoreCase("GoogleSearch")) {
				setGoogleSearch(map.get("GoogleSearch"));	
			}
			if (fields[k].getName().equalsIgnoreCase("GoogleHelp")) {
				setGoogleHelp(map.get("GoogleHelp"));	
			}
			if (fields[k].getName().equalsIgnoreCase("GoogleAbout")) {
				setGoogleAbout(map.get("GoogleAbout"));	
			}
			
		}
		System.out.println("Value of GoogleSearch is = " + getGoogleSearch());
		System.out.println("Value of GoogleHelp is = " + getGoogleHelp());
		System.out.println("Value of GoogleAbout is = " + getGoogleAbout());		
	}
	public String getGoogleSearch() {
		return GoogleSearch;
	}

	public void setGoogleSearch(String googleSearch) {
		GoogleSearch = googleSearch;
	}
	public String getGoogleHelp() {
		return GoogleHelp;
	}
	public void setGoogleHelp(String googleHelp) {
		GoogleHelp = googleHelp;
	}
	public String getGoogleAbout() {
		return GoogleAbout;
	}
	public void setGoogleAbout(String googleAbout) {
		GoogleAbout = googleAbout;
	}
	
}